package com.ponhu.ea2.goodsCenter.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ponhu.ea2.entity.PhBrand;
import com.ponhu.ea2.goodsCenter.provider.mapper.PhBrandMapper;
import com.ponhu.ea2.goodsCenter.provider.service.PhBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 * 品牌表  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-10-14
 */
@Service
public class PhBrandServiceImpl
        extends ServiceImpl<PhBrandMapper, PhBrand>
        implements PhBrandService {

    /**
     * 获取全部品牌或搜索品牌
     * 模糊匹配：品牌英文名称、品牌中文名称、别称
     *
     * @param name
     * @return
     */
    @Override
    public List<PhBrand> getPhBrandsByName(String name, Boolean isAll) {

        LambdaQueryWrapper<PhBrand> queryWrapper = Wrappers.lambdaQuery(PhBrand.class);

        if (StringUtils.isNotBlank(name))
            queryWrapper.like(PhBrand::getCnName, name).or()
                    .like(PhBrand::getEnName, name).or()
                    .like(PhBrand::getAnotherName, name);

        if (BooleanUtils.isFalse(isAll))
            queryWrapper.eq(PhBrand::getStatus, 1);

        return list(queryWrapper);
    }

}
